﻿package com.truongnha.clienttn.presentation.adapter;

import java.util.List;

import com.truongnha.clienttn.R;
import com.truongnha.clienttn.business.model.AttendModel;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AttendAdapter extends ArrayAdapter<AttendModel> {
	private final List<AttendModel> list;
	private final Activity context;

	public AttendAdapter(Activity context, List<AttendModel> list) {
		super(context, R.layout.attendance_item, list);
		this.context = context;
		this.list = list;
	}

	static class ViewHolder {
		protected TextView index;
		protected TextView status;
		protected TextView time;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.attendance_item, null);
			final ViewHolder viewHolder = new ViewHolder();

			viewHolder.index = (TextView) view.findViewById(R.id.index);
			viewHolder.status = (TextView) view.findViewById(R.id.status);
			viewHolder.time = (TextView) view.findViewById(R.id.time);
			view.setTag(viewHolder);
		} else {
			view = convertView;
		}
		ViewHolder holder = (ViewHolder) view.getTag();
		switch (list.get(position).getType()) {
		case 3:
			holder.status.setTextColor(Color.rgb(204, 0, 0));
			// holder.index.setTextColor(Color.rgb(204, 0, 0));
			holder.time.setTextColor(Color.rgb(204, 0, 0));
			holder.status.setText("Không phép");
			break;
		case 2:
			holder.status.setTextColor(Color.rgb(58, 135, 173));
			// holder.index.setTextColor(Color.rgb(58, 135, 173));
			holder.time.setTextColor(Color.rgb(58, 135, 173));
			holder.status.setText("Đi muộn");
			break;
		case 1:
			holder.status.setTextColor(Color.rgb(70, 136, 71));
			// holder.index.setTextColor(Color.rgb(70, 136, 71));
			holder.time.setTextColor(Color.rgb(70, 136, 71));
			holder.status.setText("Có phép");
			break;
		default:
			holder.status.setText(" ");
			break;
		}
		holder.index.setText((position + 1) + "");
		holder.time.setText(list.get(position).getTime());
		return view;
	}// end getView
}
